<?php
namespace WXAPI\Controller;
use Mobile\Logic\Jssdk;
use Think\Controller;
class IndexController extends BaseController {
    public function index(){
        $this->display();
    }

    /*  
     * 获取首页数据
     */
	public function cs(){
        $goods_category = M('goods_category')->where(['image'=>['neq','']])->select();

        function downloadImage($url,$fromPlatUrl)
        {
            $url = $fromPlatUrl.$url;
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
            $file = curl_exec($ch);
            curl_close($ch);
            saveAsImage($url, $file);
        }

        function saveAsImage($url, $file)
        {

            $filename = pathinfo($url, PATHINFO_BASENAME);
            $dirname = pathinfo(parse_url($url, PHP_URL_PATH), PATHINFO_DIRNAME);
            $path =   substr($dirname,1);
            $fullpath =  $path . '/' . $filename;


            // 如果目录不存在，则创建
            if(!is_dir($path)) {
                mkdir($path, 0777, true);
            }
           
            if(file_exists($fullpath)) {
                
            }else{
                $resource = fopen($fullpath, 'a');
                fwrite($resource, $file);
                fclose($resource);
            }
        }
        foreach ($goods_category as $value){
            downloadImage($value['image'],'https://huaihua.zczmer.com'); //下载大图
        }

	}



    public function home(){
          
        $basic=tpCache("basic");
        $is_show_store=$basic['app_test'];
        $is_show_bonus=$basic['is_show_bonus'];
        $show_number=$basic['show_number'];
        $finder_user=$basic['finder_user'];
        $basic_title=tpCache("shop_info");
        $shop_title=$basic_title['store_name'];
        $user_id = urldecode(trim(I('user_id','')));
        $smtp=tpCache("smtp");
        $hd_open=$smtp['regis_smtp_enable'];
        $hd_type=$smtp['regis_smtp_type'];
        $hd_content='';
        $time = time();
		
//        $quyu=M('users')->where("user_id=".$user_id)->cache(true,TPSHOP_CACHE_TIME)->getField('quyu');
        if($hd_open)
            $hd_content=htmlspecialchars_decode(\str_ireplace('src=&quot;/','src="http://cdn.jccsc.cn/',$smtp['smtp_content']));
        //$hd_content=\str_replace('http:/','',$smtp['smtp_content']);
        $where = [
            'start_time'=>['lt',time()],
            'end_time'=>['gt',time()],
            'type'=>'1',
            'is_show'=>1,
            'fenbu_id'=>['like','%"'.$this->fenbu_id.'"%']
        ];
        $template = M('template')->cache(true,TPSHOP_CACHE_TIME)->where($where)->find();
        
        // if(!empty($template)){
        //     $template['fenbu_id'] = json_decode($template['fenbu_id'],true);
        //     if(!in_array($this->fenbu_id,$template['fenbu_id'])){
        //         $template ['is_show'] = 0;
        //     }
        // }

        $hd_content=htmlspecialchars_decode($smtp['smtp_content']);
        if(empty($template)){
            $template ['is_show'] = 0;
        }
        
        $adWhere = [
            'start_time'=>['lt',$time],
            'end_time'=>['gt',$time],
            'pid'=>2,
            'enabled'=>1,
            'fenbu_id'=>['like','%"'.$this->fenbu_id.'"%']
        ];
        //获取轮播图
        $data = M('ad')->where($adWhere)->field(array('ad_link','ad_name','ad_code','pid','orderby'))->order('orderby asc')->cache(true,TPSHOP_CACHE_TIME)->select();
        //广告地址转换
        foreach($data as $k=>$v){
            $data[$k]['ad_code'] = C('MYOSS')['url'].$v['ad_code'];
            $data[$k]['link'] = $data[$k]['ad_link'];
            $data[$k]['link_type'] = 2;
            $data[$k]['is_tab'] = false;

            // if(strpos($v['ad_link'],'store_id=') !== false){
            //     $ad_link=\explode('=',$v['ad_link']);
            //     $store_id=$ad_link[1];

            //      if($store_id){
            //          $pd=M('store')->where('store_id='.$store_id)->cache(true,TPSHOP_CACHE_TIME)->find();
            //          if(strpos($pd['quyu_stop'],$this->fenbu_id) !== false)
            //              unset($data[$k]);

            //          if($pd['fenbu_id']!=$this->fenbu_id)
            //              unset($data[$k]);
            //      }
            // }
        }

        $menuWhere = [
            'pid'=>51336,
            'enabled'=>1,
            'fenbu_id'=>['like','%"'.$this->fenbu_id.'"%']
        ];
        $menu = M("ad")
        ->where($menuWhere)
        ->order("orderby ASC")
        ->cache(true,TPSHOP_CACHE_TIME)
        ->select();
        //根据不同跳转页面 采用不用打跳转方式
        foreach ($menu as $key=>$value){
            $menu[$key]['ad_code'] = C('MYOSS')['url'].$value['ad_code'];
            $menu[$key]['open_type'] ="navigate";
            if(strpos($value['ad_link'],'store_id=') !== false){
                $ad_link=\explode('=',$value['ad_link']);
                $store_id=$ad_link[1];
                if($store_id){
                    // $pd=M('store')->where('store_id='.$store_id)->cache(true,TPSHOP_CACHE_TIME)->find();
                    // if(strpos($pd['quyu_stop'],$this->fenbu_id) !== false)
                    //     unset($menu[$key]);

                    // if($pd['fenbu_id']!=$this->fenbu_id)
                    //     unset($menu[$key]);
                }

            }
        }

//    		$gonggao=M('article')->where('article_id=48')->cache(true,TPSHOP_CACHE_TIME)->getField('description');
        $gonggao=$basic && $basic['notice'] ? $basic['notice'] :'';

        //广告2
        //27,28,29,30,31
        $xianshi = M('ad')
            ->where("pid=51341 and enabled=1 and start_time<".$time." and end_time>".$time)
            ->order('orderby asc')
            ->cache(true,TPSHOP_CACHE_TIME)
            ->select(); //限时秒杀特价

        foreach ($xianshi as $key=>$value){
            $xianshi[$key]['ad_code'] = C('MYOSS')['url'].$value['ad_code'];
            $xianshi[$key]['end_time'] = time3string($value['end_time']-time());
            if(strpos($value['ad_link'],'objectId=') !== false){
                $ad_link=\explode('=',$value['ad_link']);
                $goods_id=$ad_link[1];
                $store_id=M('goods')->field('store_id,quyu_stop')->where('goods_id='.$goods_id)->cache(true,TPSHOP_CACHE_TIME)->find();
                if($store_id['store_id']){
                    $pd=M('store')->where('store_id='.$store_id['store_id'])->cache(true,TPSHOP_CACHE_TIME)->find();
                    if(strpos($pd['quyu_stop'],$this->fenbu_id) !== false)
                        unset($xianshi[$key]);

                    if(strpos($store_id['quyu_stop'],$this->fenbu_id) !== false)
                        unset($xianshi[$key]);

                    if($pd['fenbu_id']!=$this->fenbu_id)
                        unset($xianshi[$key]);
                }

            }
        }

        //获取所有每日秒杀id
        $promGoods = M('prom_goods')
            ->cache(true,TPSHOP_CACHE_TIME)->where('start_time<'.$time.' and end_time>'.$time.' and miao_status = 1')
            ->select();
        if(false){
            $promId = '';
            foreach ($promGoods as $k=>$v){
                $promId .= $v['id'].',';
            }
            $promId = substr($promId,0,strlen($promId)-1);
            //获取每日秒杀商品按热度排序

                $promGoodsList = M('goods as a')
                ->field('a.*,b.store_name,b.quyu_price,c.expression')
                ->join('ty_store b on b.store_id = a.store_id','LEFT')
                ->join('ty_prom_goods c on c.id = a.prom_id','LEFT')
                ->where("a.prom_id in ($promId) and (a.quyu_stop NOT LIKE '%\"$this->fenbu_id\"%' or a.quyu_stop IS NULL ) and a.is_on_sale = 1")
                // ->order("c.orderby ASC,a.sales_sum DESC")
                // ->order('c.orderby ASC,expression asc')
                ->order('c.orderby ASC,expression asc,a.goods_id')
                ->cache(true,TPSHOP_CACHE_TIME)
                ->limit(6)
                ->select();
            foreach ($promGoodsList as $k=>$v){//计算价格
                //找到优惠力度
              //  $prom = M('prom_goods')->where(['id'=>$v['prom_id']])->find();
                $float = check_float($v['store_id'],$this->user_id,$v['goods_id']);
                $v['floating'] = $v['floating']+$float;
                $quyu_price=quyu_price_index_home($this->area_id,$v['quyu_price'],$v['quyu_yijia']);
                $promGoodsList[$k]['shop_price']=geshi((float)$v['shop_price']*(float)$v['floating']/100*$quyu_price); //浮点计算
                $promGoodsList[$k]['shop_price_y']=geshi((float)$v['shop_price']*(float)$v['floating']/100*$quyu_price); //浮点计算
                // if(!empty($prom)){
                    //计算优惠价格
                    if($v['prom_type'] == 5){
                         $promGoodsList[$k]['shop_price'] = $promGoodsList[$k]['shop_price']*$v['expression']/100;
                    }elseif($v['prom_type'] == 2){
                        $promGoodsList[$k]['shop_price'] = $v['expression'];
                    }
                   
                // }
                // $promGoodsList[$k]['shop_price'] = $v['shop_price2'];

                if($this->area_id!=0)
                    $promGoodsList[$k]['shop_price']=$promGoodsList[$k]['shop_price']+yj_price_index_home($v['yijia_quyu'],$promGoodsList[$k]['shop_price'],$this->area_id);

                $promGoodsList[$k]['shop_price'] = geshi($promGoodsList[$k]['shop_price']);
                if($this->user_id =='61' || $this->is_lock == 1)
                    $promGoodsList[$k]['shop_price'] = '登陆查看';

                $promGoodsList[$k]['original_img'] = C('MYOSS')['url'].$v['original_img'];
                
                 $goodsFull = M('goods_full')->where("store_id = ".$v['store_id']." and start_time <=$time and end_time >=$time")->order('id desc')->find();
                if(!empty($goodsFull) && $v['prom_lock'] == 0){
                    if(!empty($goodsFull['brand_id'])){
                        $brand_id = json_decode($goodsFull['brand_id'],true);
                        if(in_array($v['brand_id'],$brand_id)){
                            $promGoodsList[$k]['full_status'] = 1;
                            $promGoodsList[$k]['full_text'] = '店铺满赠';
                        }else{
                            $promGoodsList[$k]['full_status'] = 0;
                            $promGoodsList[$k]['full_text'] = '';
                        }
                    }elseif(!empty($goodsFull['goods_id'])){
                        $goods_id = json_decode($goodsFull['goods_id'],true);
                        if(in_array($v['goods_id'],$goods_id)){
                            $promGoodsList[$k]['full_status'] = 1;
                            $promGoodsList[$k]['full_text'] = '店铺满赠';
                        }else{
                            $promGoodsList[$k]['full_status'] = 0;
                            $promGoodsList[$k]['full_text'] = '';
                        }
                    }else{
                        $promGoodsList[$k]['full_status'] = 1;
                        $promGoodsList[$k]['full_text'] = '店铺满赠';
                    }
                }else{
                    $promGoodsList[$k]['full_status'] = 0;
                    $promGoodsList[$k]['full_text'] = '';
                }
          
            }

        }else{
            $promGoodsList = [];
        }

        $adis_new = M('ad')
            ->where("pid=51335 and enabled=1 and start_time<".$time." and end_time>".$time)
            ->order('orderby asc')
            ->cache(true,TPSHOP_CACHE_TIME)
            ->select(); //天天特价
        foreach ($adis_new as $key=>$value){
            $adis_new[$key]['ad_code'] = C('MYOSS')['url'].$value['ad_code'];
            if(strpos($value['ad_link'],'objectId=') !== false){
                $ad_link=\explode('=',$value['ad_link']);
                $goods_id=$ad_link[1];

                $store_id=M('goods')->field('store_id,quyu_stop')->where('goods_id='.$goods_id)->cache(true,TPSHOP_CACHE_TIME)->find();
                if($store_id['store_id']){
                    $pd=M('store')->where('store_id='.$store_id['store_id'])->cache(true,TPSHOP_CACHE_TIME)->find();
                    if(strpos($pd['quyu_stop'],$this->fenbu_id) !== false)
                        unset($adis_new[$key]);

                    if(strpos($store_id['quyu_stop'],$this->fenbu_id) !== false)
                        unset($adis_new[$key]);

                    if($pd['fenbu_id']!=$this->fenbu_id)
                        unset($adis_new[$key]);
                }
                // $pd=M('store')->where('store_id='.$store_id.' and INSTR(quyu_stop,"\"'.$this->fenbu_id.'\"")>0')->cache(true,TPSHOP_CACHE_TIME)->find();
                // if($pd && strpos($pd['quyu_stop'],$this->fenbu_id) !== false)
                // 	unset($xianshi[$key]);
            }
            $adis_new[$key]['start_time'] = date('Y-m-d H:i:s',$value['start_time']);
            $adis_new[$key]['end_time'] = date('Y-m-d H:i:s',$value['end_time']);
        }

        $lanmu =M("ad")->field('ad_code,ad_link,bgcolor')->where("pid=51342")->cache(true,TPSHOP_CACHE_TIME)->order("orderby ASC")->select(); //栏目素材
        foreach ($lanmu as $key=>$value)
        {
            $lanmu[$key]['ad_code'] = C('MYOSS')['url'].$value['ad_code'];
        }

        $dianpu = M('ad')->where("pid=51337 and enabled=1 and start_time<".$time." and end_time>".$time)->order('orderby asc')->cache(true,TPSHOP_CACHE_TIME)->select(); //优质店铺
        foreach ($dianpu as $key=>$value)
        {
            $dianpu[$key]['ad_code'] = C('MYOSS')['url'].$value['ad_code'];
        }

        //获取大分类
        // $category_arr =array(
        //     [
        //         'title'=>'新品上架',
        //         'mytrue'=>'is_recommend'
        //     ],[
        //         'title'=>'品牌推荐',
        //         'mytrue'=>'is_new'
        //     ],[
        //         'title'=>'特推好货',
        //         'mytrue'=>'is_yanzhi'
        //     ],[
        //         'title'=>'清仓特卖',
        //         'mytrue'=>'is_qc'
        //     ]);
                    $category_arr =array(
            [
                'title'=>'新品上架',
                'mytrue'=>'is_recommend'
            ],[
                'title'=>'品牌推荐',
                'mytrue'=>'is_new'
            ],[
                'title'=>'人气推荐',
                'mytrue'=>'is_hot'
            ],[
                'title'=>'特推好货',
                'mytrue'=>'is_yanzhi'
            ],[
                'title'=>'清仓特卖',
                'mytrue'=>'is_qc'
            ]);
            
                $template['independence'] = $this->independence;
                if(!empty($user_id)){
                   $fast_flag = M('users')->where("user_id=".$user_id)->cache(true,TPSHOP_CACHE_TIME)->getField('fast_flag'); 
                }
                if ($user_id) {
                    $user = M('users')->where("user_id = {$user_id}")->cache(true,TPSHOP_CACHE_TIME)->find();
        			$discount=$user['discount'];
                }
        
        // 		if($discount){
        // 			$goods['shop_price']=$discount*$goods['shop_price'];
        // 		}
             
        foreach($category_arr as $key=> $c){
            if($c['mytrue'] == 'is_yanzhi'){
                $show_number = $show_number;
                $Asort = 'g.yanzhi_sort ASC,g.sales_sum DESC';
            }elseif($c['mytrue'] == 'is_qc'){
                $show_number = $show_number;
                $Asort = 'g.sorts ASC,g.sales_sum DESC,goods_id';
            }else{
                $Asort = 'g.sorts ASC';
            }
            $show_number=$c['is_hot'] ? 6 : $show_number;
            $show_number=$c['is_recommend'] ? 6 : $show_number;

                if($this->independence == 2){
                    $where = "g.".$c['mytrue']."=1 and g.is_on_sale=1 and g.is_delete=0 and s.store_state=1 and (INSTR(g.quyu_stop,'\"".$this->fenbu_id."\"')=0 or g.quyu_stop is NULL) and (INSTR(s.quyu_stop,'\"".$this->fenbu_id."\"')=0 or s.quyu_stop is NULL)and s.fenbu_id=$this->fenbu_id";
                }else{
                    $where = "g.".$c['mytrue']."=1 and g.is_on_sale=1 and g.is_delete=0 and s.store_state=1 and (INSTR(g.quyu_stop,'\"".$this->fenbu_id."\"')=0 or g.quyu_stop is NULL) and (INSTR(s.quyu_stop,'\"".$this->fenbu_id."\"')=0 or s.quyu_stop is NULL)and (s.fenbu_id=0 or s.fenbu_id=$this->fenbu_id)";
                }
                
         

            $category_arr[$key]['goods_list']= M('goods')->alias('g')
                ->field('g.goods_id,g.yijia_quyu,g.goods_name,g.floating,g.store_id,g.original_img,g.shop_price,g.prom_type,g.prom_id,s.store_name,s.fast_flag,g.stop_yijia,s.quyu_price,g.yijia,pg.*,g.store_id as store_id,g.goods_id as goods_id,g.brand_id,g.store_cat_id1,g.prom_lock')
                ->join('ty_store s ON g.store_id=s.store_id','left')
                ->join('ty_prom_goods pg ON g.prom_id=pg.id','left')
                ->where($where)
                ->order($Asort)->limit($show_number)
                ->cache(true,TPSHOP_CACHE_TIME)
                ->select();


            foreach($category_arr[$key]['goods_list'] as  $key1=> $d){
                $category_arr[$key]['goods_list'][$key1]['shop_price_y']=geshi((float)$d['shop_price']*(float)$d['floating']/100*$quyu_price);
                    if($discount){
            			$d['shop_price']=$discount*$d['shop_price'];
            		}
                //by sofwu 公式计算浮价
                $floating = $d['floating'];
                $d['floating'] = eval("return $floating;");

                $float = check_float($d['store_id'],$this->user_id,$d['goods_id']);
                $d['floating'] = $d['floating']+$float;
                 //判断是否有满赠活动
                $goodsFull = M('goods_full')->where("store_id = ".$d['store_id']." and start_time <=$time and end_time >=$time")->order('id desc')->find();
                if(!empty($goodsFull) && $d['prom_lock'] == 0){
                    if(!empty($goodsFull['brand_id'])){
                        $brand_id = json_decode($goodsFull['brand_id'],true);
                        if(in_array($d['store_cat_id1'],$brand_id)){
                            $category_arr[$key]['goods_list'][$key1]['full_status'] = 1;
                            $category_arr[$key]['goods_list'][$key1]['full_text'] = '店铺满赠';
                        }else{
                            $category_arr[$key]['goods_list'][$key1]['full_status'] = 0;
                            $category_arr[$key]['goods_list'][$key1]['full_text'] = '';
                        }
                    }elseif(!empty($goodsFull['goods_id'])){
                        $goods_id = json_decode($goodsFull['goods_id'],true);
                        if(in_array($d['goods_id'],$goods_id)){
                            $category_arr[$key]['goods_list'][$key1]['full_status'] = 1;
                            $category_arr[$key]['goods_list'][$key1]['full_text'] = '店铺满赠';
                        }else{
                            $category_arr[$key]['goods_list'][$key1]['full_status'] = 0;
                            $category_arr[$key]['goods_list'][$key1]['full_text'] = '';
                        }
                    }else{
                        $category_arr[$key]['goods_list'][$key1]['full_status'] = 1;
                        $category_arr[$key]['goods_list'][$key1]['full_text'] = '店铺满赠';
                    }
                }else{
                    $category_arr[$key]['goods_list'][$key1]['full_status'] = 0;
                    $category_arr[$key]['goods_list'][$key1]['full_text'] = '';
                }
                // $category_arr[$key]['goods_list'][$key1]['full_status'] = 1;
                // $category_arr[$key]['goods_list'][$key1]['full_text'] = '店铺满赠';
                $quyu_price=quyu_price_index_home($this->fenbu_id,$d['quyu_price'],0);
                $category_arr[$key]['goods_list'][$key1]['original_img'] = C('MYOSS')['url'].$d['original_img'];
                $category_arr[$key]['goods_list'][$key1]['mytrue']=$c['mytrue'];
                $category_arr[$key]['goods_list'][$key1]['shop_price']=geshi((float)$d['shop_price']*(float)$d['floating']/100*$quyu_price); //浮点计算
                $category_arr[$key]['goods_list'][$key1]['shop_pricesss'] = yj_price_index_home($d['yijia_quyu'],$category_arr[$key]['goods_list'][$key1]['shop_price'],$this->fenbu_id);
                $category_arr[$key]['goods_list'][$key1]['shop_price']=geshi($category_arr[$key]['goods_list'][$key1]['shop_price']+yj_price_index_home($d['yijia_quyu'],$category_arr[$key]['goods_list'][$key1]['shop_price'],$this->fenbu_id));

                //查询是否快线店铺
                if ($d['fast_flag'] && $fast_flag == 1){
                    $category_arr[$key]['goods_list'][$key1]['fast_text'] = '快线';
                }

                $prom_goods_price=0;
                if($this->user_id =='61' || $this->is_lock == 1)
                    $category_arr[$key]['goods_list'][$key1]['shop_price']='登陆查看'; //浮点计算

                // 首页商品优惠折扣显示 20181123 亮 START
                if ($d['prom_id']){
                    //$prom_goods = M('prom_goods')->where(array('id'=>$d['prom_id']))->find();
                    $prom_code = C('MYOSS')['url'].$d['prom_code'];
                    $statusss = 1;
                    $datass = time();
                    $d['shop_price']=(float)$d['shop_price']*(float)$d['floating']/100; //浮点计算

                        $d['shop_price']+=yj_price_index_home($d['yijia_quyu'],$d['yijia']);
                    $yj_h1 = yj_price_index_home_h1($d['yijia_quyu'],$d['yijia']);
                    if (($datass > $d['start_time']) && ($datass < $d['end_time'])){
                        if ($d['type'] == 0){
                            $prom_goods_price = geshi($d['shop_price'] * $d['expression'] / 100);
                            $prom_goods_content = 0;
                            if($yj_h1 < 0 && $d['stop_yijia'] == 1){
                                $yj_h1 = $yj_h1*100;
                                $d['expression'] = $d['expression']+$yj_h1;
                            }
                        }elseif($d['type'] == 1){
                            $prom_goods_price = $d['shop_price'] - $d['expression'];
                            $prom_goods_content = 0;
                        }elseif($d['type'] == 2){
                            $prom_goods_price = $d['expression'];
                            $prom_goods_content = 0;
                        }else{
                            $prom_goods_price = $d['shop_price'];
                            $prom_goods_content = "购买赠送代金券$d[expression]元";
                        }
                    }
                    if($prom_goods_price){
                        // $category_arr[$key]['goods_list'][$key1]['prom_goods_price'] = geshi($prom_goods_price);
                        $category_arr[$key]['goods_list'][$key1]['prom_goods_price'] = geshi($prom_goods_price);
                        $category_arr[$key]['goods_list'][$key1]['prom_goods_content'] =huodong_name($d['type'],$d['expression']);
                        $category_arr[$key]['goods_list'][$key1]['prom_code'] = $prom_code;
                        $category_arr[$key]['goods_list'][$key1]['status_status'] = $statusss;
                        
                         if($this->user_id =='61' || $this->is_lock == 1)
                             $category_arr[$key]['goods_list'][$key1]['prom_goods_price']='登陆查看'; //浮点计算
                    }
                }
                // 首页商品优惠折扣显示 20181123 亮 END
            }
        }
        //echo \json_encode($category_arr);exit;
        //获取优惠券
        $user_id = I("user_id",0); // 用户id
        //$coupon=$this->getReceiveCoupon($user_id);
        $types=M('goods_category')->cache(true,TPSHOP_CACHE_TIME)->where('parent_id=0 and is_show=1 and is_hot=1')->order('sort_order asc')->select();
        //  $tetui = M("ad")->field('start_time,end_time')->where("ad_id=38")->cache(true,TPSHOP_CACHE_TIME)->find(); //栏目素材
        // if($tetui['start_time'] > $time || $tetui['end_time'] < $time){
        //     $category_arr[3]['goods_list'] = [];
        // }
        $category_arr[0]['goods_list'] = [];
        $category_arr[4]['goods_list'] = [];
        //获取拼团活动
        //$pintuan=$this->getPintTypeList();"pintuan"=>$pintuan,
        if($this->user_id =='61' || $this->is_lock == 1){
            $template['is_show'] = 0;
            $adis_new=[];
            $data=[];
            $dianpu=[];
        }
        $coupon_diff = $this->getCouponInfo($this->user_id);
        if($this->user_id !='61' ){
            M('store_liulan')->add(array(
            'user_id'=>$this->user_id,
            'add_time'=>time(),
			));
        }
        
        //获取电话
        exit(json_encode(array('status'=>1,'msg'=>'获取成功','result'=>array('goods'=>$category_arr,'preferential'=>$preferential,'ad'=>$data,"menu"=>$menu,"is_show_store"=>$is_show_store,"is_show_bonus"=>$is_show_bonus,'shop_title'=>$shop_title,'hd_open'=>$hd_open,'hd_bg'=>$hd_bg,'hd_type'=>$hd_type,'bg_height'=>$bg_height,'hd_content'=>$hd_content, 'finder_user'=>$finder_user,'hd_open_new'=>$template['is_show'],'smtp_bg_new'=>$template['smtp_bg'],'bg_height_new'=>$template['bg_height'], 'hd_content_new'=>$template['content']),"types"=>$types,"gonggao"=>$gonggao,"dianpu"=>$dianpu,'promGoodsList'=>$promGoodsList,'adis_new'=>$adis_new,'lanmu'=>$lanmu,'pinpai'=>$pinpai,'xianshi'=>$xianshi,'tel'=>$basic['wxtel'],'system_status'=>['open'=>$basic['system_open'],'content'=>$basic['system_content']],'coupon_diff'=>$coupon_diff)));

//        exit(json_encode(array('status'=>1,'msg'=>'获取成功','result'=>array('goods'=>$category_arr,'ad'=>array_values($data),"menu"=>$menu,"is_show_store"=>$is_show_store,"is_show_bonus"=>$is_show_bonus,'shop_title'=>$shop_title,'hd_open'=>$hd_open,'hd_bg'=>$smtp['smtp_bg'],'hd_type'=>$smtp['regis_smtp_type'],'bg_height'=>$smtp['bg_height'], 'hd_content'=>$hd_content, 'finder_user'=>$finder_user),"types"=>$types,"gonggao"=>$gonggao,"dianpu"=>$dianpu,'adis_new'=>$adis_new,'lanmu'=>$lanmu,'xianshi'=>$xianshi)));
    }
     /*
    *关注商品
    */
    public function goodsFollow(){
        $page = I('page',1);
        $limit = I('limit',10);
        if($page == 1){
            $page = 0;
        }else{
            $page = $page-1;
        }
         $user_id = $this->user_id;
       
        if($user_id == 61){
            //没登录返回空
            $json = [];
            $json['status'] = 1;
            $json['msg'] = '获取成功';
            $json['result'] = [];
            $this->ajaxReturn($json);
        }
        $showPage = $page*$limit;
        $storeGoods = M('store_collect c')
        ->field('c.*,s.store_logo')
        ->cache(true,500)
        ->join('ty_store s on s.store_id = c.store_id','left')
        ->order('c.add_time desc')
        ->where('c.user_id='.$user_id)
        ->limit($showPage,$limit)
        ->order('c.add_time desc')
        ->select();
        if(!empty($storeGoods)){
            foreach ($storeGoods as $k=>$v){
                $storeGoods[$k]['store_logo'] = C('MYOSS')['url2'].$v['store_logo'];
                $storeGoods[$k]['goods'] = M('goods')->cache(true,TPSHOP_CACHE_TIME)->where(['store_id'=>$v['store_id']])->limit(6)->order('sales_sum desc')->select();
                foreach ($storeGoods[$k]['goods'] as $key=>$val){
                    $storeGoods[$k]['goods'][$key]['original_img'] = C('MYOSS')['url'].$val['original_img'];;
                }
            }
        }
        $json = [];
        $json['status'] = 1;
        $json['msg'] = '获取成功';
        $json['result'] = ['storeGoods'=>$storeGoods,'page'=>I('page'),'limit'=>$limit];
        $this->ajaxReturn($json);
    }
    public function wx_open(){
        $basic=tpCache("basic");
        $return_arr = [];
        $return_arr['code'] = 1;
        $return_arr['msg'] = '获取成功';
        $return_arr['data'] = $basic['wx_open'];
        $this->ajaxReturn($return_arr);
    }
    /**
     * 新品上架
     * */
    public function recommendGoodsList(){
        $page = I('p',1);
        $limit = I('limit',10);
        if($page == 1){
            $page = 0;
        }else{
            $page = $page-1;
        }
        $showPage = $page*$limit;
        $user_id = $this->user_id;
        if ($user_id) {
            $user = M('users')->where("user_id = {$user_id}")->cache(true,TPSHOP_CACHE_TIME)->find();
			$discount=$user['discount'];
        }

		
        $time = time();
        $where = "g.is_new=1 and g.is_on_sale=1 and g.is_delete=0 and s.store_state=1 and (INSTR(g.quyu_stop,'\"".$this->fenbu_id."\"')=0 or g.quyu_stop is NULL) and (INSTR(s.quyu_stop,'\"".$this->fenbu_id."\"')=0 or s.quyu_stop is NULL)and (s.fenbu_id=0 or s.fenbu_id=$this->fenbu_id)";
         $Asort = 'g.sorts ASC';
        $goods_list= M('goods')->alias('g')
                ->field('g.goods_id,g.yijia_quyu,g.goods_name,g.floating,g.store_id,g.original_img,g.shop_price,g.prom_type,g.prom_id,s.store_name,s.fast_flag,g.stop_yijia,s.quyu_price,g.yijia,pg.*,g.store_id as store_id,g.goods_id as goods_id,g.brand_id,g.store_cat_id1,g.prom_lock')
                ->join('ty_store s ON g.store_id=s.store_id','left')
                ->join('ty_prom_goods pg ON g.prom_id=pg.id','left')
                ->where($where)
                ->order($Asort)
                ->limit($showPage,$limit)
                ->cache(true,TPSHOP_CACHE_TIME)
                ->select();
          foreach($goods_list as  $key1=> $d){
                if($discount){
        			$d['shop_price']=$discount*$d['shop_price'];
        		}
                //by sofwu 公式计算浮价
                $floating = $d['floating'];
                $d['floating'] = eval("return $floating;");

                $float = check_float($d['store_id'],$this->user_id,$d['goods_id']);
                $d['floating'] = $d['floating']+$float;

                $quyu_price=quyu_price_index_home($this->fenbu_id,$d['quyu_price'],0);
                $goods_list[$key1]['original_img'] = C('MYOSS')['url'].$d['original_img'];
                $goods_list[$key1]['mytrue']=$c['mytrue'];
                $goods_list[$key1]['shop_price']=geshi((float)$d['shop_price']*(float)$d['floating']/100*$quyu_price); //浮点计算
                $goods_list[$key1]['shop_pricesss'] = yj_price_index_home($d['yijia_quyu'],$goods_list[$key1]['shop_price'],$this->fenbu_id);
                $goods_list[$key1]['shop_price']=geshi($goods_list[$key1]['shop_price']+yj_price_index_home($d['yijia_quyu'],$goods_list[$key1]['shop_price'],$this->fenbu_id));

                //查询是否快线店铺
                if ($d['fast_flag'] && $fast_flag == 1){
                    $goods_list[$key1]['fast_text'] = '快线';
                }
                
                $goodsFull = M('goods_full')->where("store_id = ".$d['store_id']." and start_time <=$time and end_time >=$time")->order('id desc')->find();
                if(!empty($goodsFull) && $d['prom_lock'] == 0){
                    if(!empty($goodsFull['brand_id'])){
                        $brand_id = json_decode($goodsFull['brand_id'],true);
                        if(in_array($d['store_cat_id1'],$brand_id)){
                            $goods_list[$key1]['full_status'] = 1;
                            $goods_list[$key1]['full_text'] = '店铺满赠';
                        }else{
                            $goods_list[$key1]['full_status'] = 0;
                            $goods_list[$key1]['full_text'] = '';
                        }
                    }elseif(!empty($goodsFull['goods_id'])){
                        $goods_id = json_decode($goodsFull['brand_id'],true);
                        if(in_array($d['goods_id'],$goods_id)){
                            $goods_list[$key1]['full_status'] = 1;
                            $goods_list[$key1]['full_text'] = '店铺满赠';
                        }else{
                            $goods_list[$key1]['full_status'] = 0;
                            $goods_list[$key1]['full_text'] = '';
                        }
                    }else{
                        $goods_list[$key1]['full_status'] = 1;
                        $goods_list[$key1]['full_text'] = '店铺满赠';
                    }
                }else{
                    $goods_list[$key1]['full_status'] = 0;
                    $goods_list[$key1]['full_text'] = '';
                }

                $prom_goods_price=0;
                if($this->user_id =='61' || $this->is_lock == 1)
                    $goods_list[$key1]['shop_price']='登陆查看'; //浮点计算

                // 首页商品优惠折扣显示 20181123 亮 START
                if ($d['prom_id']){
                    //$prom_goods = M('prom_goods')->where(array('id'=>$d['prom_id']))->find();
                    $prom_code = C('MYOSS')['url'].$d['prom_code'];
                    $statusss = 1;
                    $datass = time();
                    $d['shop_price']=(float)$d['shop_price']*(float)$d['floating']/100; //浮点计算

                        $d['shop_price']+=yj_price_index_home($d['yijia_quyu'],$d['yijia']);
                    $yj_h1 = yj_price_index_home_h1($d['yijia_quyu'],$d['yijia']);
                    if (($datass > $d['start_time']) && ($datass < $d['end_time'])){
                        if ($d['type'] == 0){
                            $prom_goods_price = geshi($d['shop_price'] * $d['expression'] / 100);
                            $prom_goods_content = 0;
                            if($yj_h1 < 0 && $d['stop_yijia'] == 1){
                                $yj_h1 = $yj_h1*100;
                                $d['expression'] = $d['expression']+$yj_h1;
                            }
                        }elseif($d['type'] == 1){
                            $prom_goods_price = $d['shop_price'] - $d['expression'];
                            $prom_goods_content = 0;
                        }elseif($d['type'] == 2){
                            $prom_goods_price = $d['expression'];
                            $prom_goods_content = 0;
                        }else{
                            $prom_goods_price = $d['shop_price'];
                            $prom_goods_content = "购买赠送代金券$d[expression]元";
                        }
                    }
                    if($prom_goods_price){
                        $goods_list[$key1]['prom_goods_price'] = geshi($prom_goods_price);
                        $goods_list[$key1]['prom_goods_content'] =huodong_name($d['type'],$d['expression']);
                        $goods_list[$key1]['prom_code'] = $prom_code;
                        $goods_list[$key1]['status_status'] = $statusss;
                        
                         if($this->user_id =='61' || $this->is_lock == 1)
                             $goods_list[$key1]['prom_goods_price']='登陆查看'; //浮点计算
                    }
                }
                // 首页商品优惠折扣显示 20181123 亮 END
            }
            
            $return_arr = array(
                'status' => 1,
                'msg'   => '获取成功',
                'result'  => $goods_list,
                'page'=>I('page',1),
                'limit'=>$limit,
            );
            $this->ajaxReturn($return_arr);
    }
        /**
     * 品牌推荐
     * */

    public function is_hotGoodsList(){
        $page = I('p',1);
        $limit = I('limit',10);
        if($page == 1){
            $page = 0;
        }else{
            $page = $page-1;
        }
        $showPage = $page*$limit;
        $user_id = $this->user_id;
        if ($user_id) {
            $user = M('users')->where("user_id = {$user_id}")->cache(true,TPSHOP_CACHE_TIME)->find();
			$discount=$user['discount'];
        }
        $time = time();
        $where = "g.is_hot=1 and g.is_on_sale=1 and g.is_delete=0 and s.store_state=1 and (INSTR(g.quyu_stop,'\"".$this->fenbu_id."\"')=0 or g.quyu_stop is NULL) and (INSTR(s.quyu_stop,'\"".$this->fenbu_id."\"')=0 or s.quyu_stop is NULL)and (s.fenbu_id=0 or s.fenbu_id=$this->fenbu_id)";
         $Asort = 'g.sorts ASC';
        $goods_list= M('goods')->alias('g')
                ->field('g.goods_id,g.yijia_quyu,g.goods_name,g.floating,g.store_id,g.original_img,g.shop_price,g.prom_type,g.prom_id,s.store_name,s.fast_flag,g.stop_yijia,s.quyu_price,g.yijia,pg.*,g.store_id as store_id,g.goods_id as goods_id,g.store_cat_id1,g.prom_lock')
                ->join('ty_store s ON g.store_id=s.store_id','left')
                ->join('ty_prom_goods pg ON g.prom_id=pg.id','left')
                ->where($where)
                ->order($Asort)
                ->limit($showPage,$limit)
                ->cache(true,TPSHOP_CACHE_TIME)
                ->select();
          foreach($goods_list as  $key1=> $d){
                if($discount){
        			$d['shop_price']=$discount*$d['shop_price'];
        		}
                //by sofwu 公式计算浮价
                $floating = $d['floating'];
                $d['floating'] = eval("return $floating;");
                $float = check_float($d['store_id'],$this->user_id,$d['goods_id']);
                $d['floating'] = $d['floating']+$float;


                $goodsFull = M('goods_full')->where("store_id = ".$d['store_id']." and start_time <=$time and end_time >=$time")->order('id desc')->find();
                if(!empty($goodsFull) && $d['prom_lock'] == 0){
                    if(!empty($goodsFull['brand_id'])){
                        $brand_id = json_decode($goodsFull['brand_id'],true);
                        if(in_array($d['store_cat_id1'],$brand_id)){
                            $goods_list[$key1]['full_status'] = 1;
                            $goods_list[$key1]['full_text'] = '店铺满赠';
                        }else{
                            $goods_list[$key1]['full_status'] = 0;
                            $goods_list[$key1]['full_text'] = '';
                        }
                    }elseif(!empty($goodsFull['goods_id'])){
                        $goods_id = json_decode($goodsFull['goods_id'],true);
                        if(in_array($d['goods_id'],$goods_id)){
                            $goods_list[$key1]['full_status'] = 1;
                            $goods_list[$key1]['full_text'] = '店铺满赠';
                        }else{
                            $goods_list[$key1]['full_status'] = 0;
                            $goods_list[$key1]['full_text'] = '';
                        }
                    }else{
                        $goods_list[$key1]['full_status'] = 1;
                        $goods_list[$key1]['full_text'] = '店铺满赠';
                    }
                }else{
                    $goods_list[$key1]['full_status'] = 0;
                    $goods_list[$key1]['full_text'] = '';
                }
                $quyu_price=quyu_price_index_home($this->fenbu_id,$d['quyu_price'],0);
                $goods_list[$key1]['original_img'] = C('MYOSS')['url'].$d['original_img'];
                $goods_list[$key1]['mytrue']=$c['mytrue'];
                $goods_list[$key1]['shop_price']=geshi((float)$d['shop_price']*(float)$d['floating']/100*$quyu_price); //浮点计算
                $goods_list[$key1]['shop_pricesss'] = yj_price_index_home($d['yijia_quyu'],$goods_list[$key1]['shop_price'],$this->fenbu_id);
                $goods_list[$key1]['shop_price']=geshi($goods_list[$key1]['shop_price']+yj_price_index_home($d['yijia_quyu'],$goods_list[$key1]['shop_price'],$this->fenbu_id));

                //查询是否快线店铺
                if ($d['fast_flag'] && $fast_flag == 1){
                    $goods_list[$key1]['fast_text'] = '快线';
                }

                $prom_goods_price=0;
                if($this->user_id =='61' || $this->is_lock == 1)
                    $goods_list[$key1]['shop_price']='登陆查看'; //浮点计算

                // 首页商品优惠折扣显示 20181123 亮 START
                if ($d['prom_id']){
                    //$prom_goods = M('prom_goods')->where(array('id'=>$d['prom_id']))->find();
                    $prom_code = C('MYOSS')['url'].$d['prom_code'];
                    $statusss = 1;
                    $datass = time();
                    $d['shop_price']=(float)$d['shop_price']*(float)$d['floating']/100; //浮点计算

                        $d['shop_price']+=yj_price_index_home($d['yijia_quyu'],$d['yijia']);
                    $yj_h1 = yj_price_index_home_h1($d['yijia_quyu'],$d['yijia']);
                    if (($datass > $d['start_time']) && ($datass < $d['end_time'])){
                        if ($d['type'] == 0){
                            $prom_goods_price = geshi($d['shop_price'] * $d['expression'] / 100);
                            $prom_goods_content = 0;
                            if($yj_h1 < 0 && $d['stop_yijia'] == 1){
                                $yj_h1 = $yj_h1*100;
                                $d['expression'] = $d['expression']+$yj_h1;
                            }
                        }elseif($d['type'] == 1){
                            $prom_goods_price = $d['shop_price'] - $d['expression'];
                            $prom_goods_content = 0;
                        }elseif($d['type'] == 2){
                            $prom_goods_price = $d['expression'];
                            $prom_goods_content = 0;
                        }else{
                            $prom_goods_price = $d['shop_price'];
                            $prom_goods_content = "购买赠送代金券$d[expression]元";
                        }
                    }
                    if($prom_goods_price){
                        $goods_list[$key1]['prom_goods_price'] = geshi($prom_goods_price);
                        $goods_list[$key1]['prom_goods_content'] =huodong_name($d['type'],$d['expression']);
                        $goods_list[$key1]['prom_code'] = $prom_code;
                        $goods_list[$key1]['status_status'] = $statusss;
                        
                         if($this->user_id =='61' || $this->is_lock == 1)
                             $goods_list[$key1]['prom_goods_price']='登陆查看'; //浮点计算
                    }
                }
                // 首页商品优惠折扣显示 20181123 亮 END
            }
            
            $return_arr = array(
                'status' => 1,
                'msg'   => '获取成功',
                'result'  => $goods_list,
                'page'=>I('page',1),
                'limit'=>$limit,
            );
            $this->ajaxReturn($return_arr);
    }
    
    
    /**
     * 品牌推荐
     * */

    public function is_newGoodsList(){
        $page = I('p',1);
        $limit = I('limit',10);
        if($page == 1){
            $page = 0;
        }else{
            $page = $page-1;
        }
        $showPage = $page*$limit;
        $user_id = $this->user_id;
        if ($user_id) {
            $user = M('users')->where("user_id = {$user_id}")->cache(true,TPSHOP_CACHE_TIME)->find();
			$discount=$user['discount'];
        }
        $time = time();
        $where = "g.is_recommend=1 and g.is_on_sale=1 and g.is_delete=0 and s.store_state=1 and (INSTR(g.quyu_stop,'\"".$this->fenbu_id."\"')=0 or g.quyu_stop is NULL) and (INSTR(s.quyu_stop,'\"".$this->fenbu_id."\"')=0 or s.quyu_stop is NULL)and (s.fenbu_id=0 or s.fenbu_id=$this->fenbu_id)";
         $Asort = 'g.sorts ASC';
        $goods_list= M('goods')->alias('g')
                ->field('g.goods_id,g.yijia_quyu,g.goods_name,g.floating,g.store_id,g.original_img,g.shop_price,g.prom_type,g.prom_id,s.store_name,s.fast_flag,g.stop_yijia,s.quyu_price,g.yijia,pg.*,g.store_id as store_id,g.goods_id as goods_id,g.store_cat_id1,g.prom_lock')
                ->join('ty_store s ON g.store_id=s.store_id','left')
                ->join('ty_prom_goods pg ON g.prom_id=pg.id','left')
                ->where($where)
                ->order($Asort)
                ->limit($showPage,$limit)
                ->cache(true,TPSHOP_CACHE_TIME)
                ->select();
          foreach($goods_list as  $key1=> $d){
                if($discount){
        			$d['shop_price']=$discount*$d['shop_price'];
        		}
                //by sofwu 公式计算浮价
                $floating = $d['floating'];
                $d['floating'] = eval("return $floating;");
              $float = check_float($d['store_id'],$this->user_id,$d['goods_id']);
              $d['floating'] = $d['floating']+$float;
                 $goodsFull = M('goods_full')->where("store_id = ".$d['store_id']." and start_time <=$time and end_time >=$time")->order('id desc')->find();
                if(!empty($goodsFull) && $d['prom_lock'] == 0){
                    if(!empty($goodsFull['brand_id'])){
                        $brand_id = json_decode($goodsFull['brand_id'],true);
                        if(in_array($d['store_cat_id1'],$brand_id)){
                            $goods_list[$key1]['full_status'] = 1;
                            $goods_list[$key1]['full_text'] = '店铺满赠';
                        }else{
                            $goods_list[$key1]['full_status'] = 0;
                            $goods_list[$key1]['full_text'] = '';
                        }
                    }elseif(!empty($goodsFull['goods_id'])){
                        $goods_id = json_decode($goodsFull['goods_id'],true);
                        if(in_array($d['goods_id'],$goods_id)){
                            $goods_list[$key1]['full_status'] = 1;
                            $goods_list[$key1]['full_text'] = '店铺满赠';
                        }else{
                            $goods_list[$key1]['full_status'] = 0;
                            $goods_list[$key1]['full_text'] = '';
                        }
                    }else{
                        $goods_list[$key1]['full_status'] = 1;
                        $goods_list[$key1]['full_text'] = '店铺满赠';
                    }
                }else{
                    $goods_list[$key1]['full_status'] = 0;
                    $goods_list[$key1]['full_text'] = '';
                }
                $quyu_price=quyu_price_index_home($this->fenbu_id,$d['quyu_price'],0);
                $goods_list[$key1]['original_img'] = C('MYOSS')['url'].$d['original_img'];
                $goods_list[$key1]['mytrue']=$c['mytrue'];
                $goods_list[$key1]['shop_price']=geshi((float)$d['shop_price']*(float)$d['floating']/100*$quyu_price); //浮点计算
                $goods_list[$key1]['shop_pricesss'] = yj_price_index_home($d['yijia_quyu'],$goods_list[$key1]['shop_price'],$this->fenbu_id);
                $goods_list[$key1]['shop_price']=geshi($goods_list[$key1]['shop_price']+yj_price_index_home($d['yijia_quyu'],$goods_list[$key1]['shop_price'],$this->fenbu_id));

                //查询是否快线店铺
                if ($d['fast_flag'] && $fast_flag == 1){
                    $goods_list[$key1]['fast_text'] = '快线';
                }

                $prom_goods_price=0;
                if($this->user_id =='61' || $this->is_lock == 1)
                    $goods_list[$key1]['shop_price']='登陆查看'; //浮点计算

                // 首页商品优惠折扣显示 20181123 亮 START
                if ($d['prom_id']){
                    //$prom_goods = M('prom_goods')->where(array('id'=>$d['prom_id']))->find();
                    $prom_code = C('MYOSS')['url'].$d['prom_code'];
                    $statusss = 1;
                    $datass = time();
                    $d['shop_price']=(float)$d['shop_price']*(float)$d['floating']/100; //浮点计算

                        $d['shop_price']+=yj_price_index_home($d['yijia_quyu'],$d['yijia']);
                    $yj_h1 = yj_price_index_home_h1($d['yijia_quyu'],$d['yijia']);
                    if (($datass > $d['start_time']) && ($datass < $d['end_time'])){
                        if ($d['type'] == 0){
                            $prom_goods_price = geshi($d['shop_price'] * $d['expression'] / 100);
                            $prom_goods_content = 0;
                            if($yj_h1 < 0 && $d['stop_yijia'] == 1){
                                $yj_h1 = $yj_h1*100;
                                $d['expression'] = $d['expression']+$yj_h1;
                            }
                        }elseif($d['type'] == 1){
                            $prom_goods_price = $d['shop_price'] - $d['expression'];
                            $prom_goods_content = 0;
                        }elseif($d['type'] == 2){
                            $prom_goods_price = $d['expression'];
                            $prom_goods_content = 0;
                        }else{
                            $prom_goods_price = $d['shop_price'];
                            $prom_goods_content = "购买赠送代金券$d[expression]元";
                        }
                    }
                    if($prom_goods_price){
                        $goods_list[$key1]['prom_goods_price'] = geshi($prom_goods_price);
                        $goods_list[$key1]['prom_goods_content'] =huodong_name($d['type'],$d['expression']);
                        $goods_list[$key1]['prom_code'] = $prom_code;
                        $goods_list[$key1]['status_status'] = $statusss;
                        
                         if($this->user_id =='61' || $this->is_lock == 1)
                             $goods_list[$key1]['prom_goods_price']='登陆查看'; //浮点计算
                    }
                }
                // 首页商品优惠折扣显示 20181123 亮 END
            }
            
            $return_arr = array(
                'status' => 1,
                'msg'   => '获取成功',
                'result'  => $goods_list,
                'page'=>I('page',1),
                'limit'=>$limit,
            );
            $this->ajaxReturn($return_arr);
    }
    
    
    /**
     * 每日秒杀
     * */
    public function dailyKill(){
        $type = I('type');
        $page = I('p',1);
        $limit = I('limit',10);
        if($page == 1){
            $page = 0;
        }else{
            $page = $page-1;
        }
        $showPage = $page*$limit;
        $user_id = $this->user_id;
        if ($user_id) {
            $user = M('users')->where("user_id = {$user_id}")->cache(true,TPSHOP_CACHE_TIME)->find();
			$discount=$user['discount'];
        }
        $time = time();
        if($type=='tetui'){
            $fast_flag = M('users')->where("user_id=".$this->user_id)->cache(true,TPSHOP_CACHE_TIME)->getField('fast_flag');
            $where = "g.is_qc=1 and g.is_on_sale=1 and g.is_delete=0 and s.store_state=1 and (INSTR(g.quyu_stop,'\"".$this->fenbu_id."\"')=0 or g.quyu_stop is NULL) and (INSTR(s.quyu_stop,'\"".$this->fenbu_id."\"')=0 or s.quyu_stop is NULL)and (s.fenbu_id=0 or s.fenbu_id=$this->fenbu_id)";
            $promGoodsList= M('goods')->alias('g')
                ->field('pg.*,g.goods_id,g.yijia_quyu,g.goods_name,g.floating,g.store_id as store_id,g.original_img,g.shop_price,g.prom_type,g.prom_id,s.store_name,s.fast_flag,s.quyu_price,g.yijia,g.brand_id,g.store_cat_id1,g.prom_lock')
                ->join('ty_store s ON g.store_id=s.store_id','left')
                ->join('ty_prom_goods pg ON g.prom_id=pg.id','left')
                ->where($where)
                ->order('g.yanzhi_sort ASC,g.sales_sum DESC,goods_id')
                ->limit($showPage,$limit)
                ->cache(true,TPSHOP_CACHE_TIME)
                ->select();
                foreach($promGoodsList as  $key1=> $d){
                    if($discount){
            			$d['shop_price']=$discount*$d['shop_price'];
            		}
                    //by sofwu 公式计算浮价
                    $floating = $d['floating'];
                    $d['floating'] = eval("return $floating;");
                    $float = check_float($d['store_id'],$this->user_id,$d['goods_id']);
                    $d['floating'] = $d['floating']+$float;
                    $goodsFull = M('goods_full')->where("store_id = ".$d['store_id']." and start_time <=$time and end_time >=$time")->order('id desc')->find();
                    if(!empty($goodsFull) && $d['prom_lock'] == 0){
                        if(!empty($goodsFull['brand_id'])){
                            $brand_id = json_decode($goodsFull['brand_id'],true);
                            if(in_array($d['store_cat_id1'],$brand_id)){
                                $promGoodsList[$key1]['full_status'] = 1;
                                $promGoodsList[$key1]['full_text'] = '店铺满赠';
                            }else{
                                $promGoodsList[$key1]['full_status'] = 0;
                                $promGoodsList[$key1]['full_text'] = '';
                            }
                        }elseif(!empty($goodsFull['goods_id'])){
                            $goods_id = json_decode($goodsFull['goods_id'],true);
                            if(in_array($d['goods_id'],$goods_id)){
                                $promGoodsList[$key1]['full_status'] = 1;
                                $promGoodsList[$key1]['full_text'] = '店铺满赠';
                            }else{
                                $promGoodsList[$key1]['full_status'] = 0;
                                $promGoodsList[$key1]['full_text'] = '';
                            }
                        }else{
                            $promGoodsList[$key1]['full_status'] = 1;
                            $promGoodsList[$key1]['full_text'] = '店铺满赠';
                        }
                    }else{
                        $promGoodsList[$key1]['full_status'] = 0;
                        $promGoodsList[$key1]['full_text'] = '';
                    }
                    
                    $quyu_price=quyu_price_index_home($this->fenbu_id,$d['quyu_price'],0);
                    $promGoodsList[$key1]['original_img'] = C('MYOSS')['url'].$d['original_img'];
                    // $promGoodsList[$key1]['mytrue']=$c['mytrue'];
                    $promGoodsList[$key1]['shop_price']=geshi((float)$d['shop_price']*(float)$d['floating']/100*$quyu_price); //浮点计算
                    $promGoodsList[$key1]['shop_pricesss'] = yj_price_index_home($d['yijia_quyu'],$promGoodsList[$key1]['shop_price'],$this->fenbu_id);
                    $promGoodsList[$key1]['shop_price']=geshi($promGoodsList[$key1]['shop_price']+yj_price_index_home($d['yijia_quyu'],$promGoodsList[$key1]['shop_price'],$this->fenbu_id));
    
                    //查询是否快线店铺
                    if ($d['fast_flag'] && $fast_flag == 1){
                        $promGoodsList[$key1]['fast_text'] = '快线';
                    }
    
                    $prom_goods_price=0;
                    if($this->user_id =='61' || $this->is_lock == 1)
                        $promGoodsList[$key1]['shop_price']='登陆查看'; //浮点计算
    
                    // 首页商品优惠折扣显示 20181123 亮 START
                    if ($d['prom_id']){
                        //$prom_goods = M('prom_goods')->where(array('id'=>$d['prom_id']))->find();
                        $prom_code = C('MYOSS')['url'].$d['prom_code'];
                        $statusss = 1;
                        $datass = time();
                        $d['shop_price']=(float)$d['shop_price']*(float)$d['floating']/100; //浮点计算
    
                            $d['shop_price']+=yj_price_index_home($d['yijia_quyu'],$d['yijia']);
    
                        if (($datass > $d['start_time']) && ($datass < $d['end_time'])){
                            if ($d['type'] == 0){
                                $prom_goods_price = geshi($d['shop_price'] * $d['expression'] / 100);
                                $prom_goods_content = 0;
                            }elseif($d['type'] == 1){
                                $prom_goods_price = $d['shop_price'] - $d['expression'];
                                $prom_goods_content = 0;
                            }elseif($d['type'] == 2){
                                $prom_goods_price = $d['expression'];
                                $prom_goods_content = 0;
                            }else{
                                $prom_goods_price = $d['shop_price'];
                                $prom_goods_content = "购买赠送代金券$d[expression]元";
                            }
                        }
                        if($prom_goods_price){
                            $promGoodsList[$key1]['prom_goods_price'] = geshi($prom_goods_price);
                            $promGoodsList[$key1]['prom_goods_content'] =huodong_name($d['type'],$d['expression']);
                            $promGoodsList[$key1]['prom_code'] = $prom_code;
                            $promGoodsList[$key1]['status_status'] = $statusss;
                            
                             if($this->user_id =='61' || $this->is_lock == 1)
                                 $promGoodsList[$key1]['prom_goods_price']='登陆查看'; //浮点计算
                        }
                    }
                    // 首页商品优惠折扣显示 20181123 亮 END
                }
            exit(json_encode(array('status'=>1,'msg'=>'获取成功','result'=>$promGoodsList))); 
        }elseif($type=='qingcang'){
            $fast_flag = M('users')->where("user_id=".$this->user_id)->cache(true,TPSHOP_CACHE_TIME)->getField('fast_flag');
            $where = "g.is_qc=1 and g.is_on_sale=1 and g.is_delete=0 and s.store_state=1 and (INSTR(g.quyu_stop,'\"".$this->fenbu_id."\"')=0 or g.quyu_stop is NULL) and (INSTR(s.quyu_stop,'\"".$this->fenbu_id."\"')=0 or s.quyu_stop is NULL)and (s.fenbu_id=0 or s.fenbu_id=$this->fenbu_id)";
            $promGoodsList= M('goods')->alias('g')
                ->field('pg.*,g.goods_id,g.yijia_quyu,g.goods_name,g.floating,g.store_id,g.original_img,g.shop_price,g.prom_type,g.prom_id,s.store_name,s.fast_flag,s.quyu_price,g.yijia,g.store_cat_id1,g.prom_lock')
                ->join('ty_store s ON g.store_id=s.store_id')
                ->join('ty_prom_goods pg ON g.prom_id=pg.id','left')
                ->where($where)
                ->order('g.sorts ASC,g.sales_sum DESC,goods_id')
                ->limit($showPage,$limit)
                ->cache(true,TPSHOP_CACHE_TIME)
                ->select();
                foreach($promGoodsList as  $key1=> $d){
                    if($discount){
            			$d['shop_price']=$discount*$d['shop_price'];
            		}
                    //by sofwu 公式计算浮价
                    $floating = $d['floating'];
                    $d['floating'] = eval("return $floating;");
                    $float = check_float($d['store_id'],$this->user_id,$d['goods_id']);
                    $d['floating'] = $d['floating']+$float;
                    $quyu_price=quyu_price_index_home($this->fenbu_id,$d['quyu_price'],0);
                    $promGoodsList[$key1]['original_img'] = C('MYOSS')['url'].$d['original_img'];
                    // $promGoodsList[$key1]['mytrue']=$c['mytrue'];
                    $promGoodsList[$key1]['shop_price']=geshi((float)$d['shop_price']*(float)$d['floating']/100*$quyu_price); //浮点计算
                    $promGoodsList[$key1]['shop_pricesss'] = yj_price_index_home($d['yijia_quyu'],$promGoodsList[$key1]['shop_price'],$this->fenbu_id);
                    $promGoodsList[$key1]['shop_price']=geshi($promGoodsList[$key1]['shop_price']+yj_price_index_home($d['yijia_quyu'],$promGoodsList[$key1]['shop_price'],$this->fenbu_id));
    
                    //查询是否快线店铺
                    if ($d['fast_flag'] && $fast_flag == 1){
                        $promGoodsList[$key1]['fast_text'] = '快线';
                    }
                     $goodsFull = M('goods_full')->where("store_id = ".$d['store_id']." and start_time <=$time and end_time >=$time")->order('id desc')->find();
                    if(!empty($goodsFull) && $d['prom_lock'] == 0){
                        if(!empty($goodsFull['brand_id'])){
                            $brand_id = json_decode($goodsFull['brand_id'],true);
                            if(in_array($d['store_cat_id1'],$brand_id)){
                                $promGoodsList[$key1]['full_status'] = 1;
                                $promGoodsList[$key1]['full_text'] = '店铺满赠';
                            }else{
                                $promGoodsList[$key1]['full_status'] = 0;
                                $promGoodsList[$key1]['full_text'] = '';
                            }
                        }elseif(!empty($goodsFull['goods_id'])){
                            $goods_id = json_decode($goodsFull['goods_id'],true);
                            if(in_array($d['goods_id'],$goods_id)){
                                $promGoodsList[$key1]['full_status'] = 1;
                                $promGoodsList[$key1]['full_text'] = '店铺满赠';
                            }else{
                                $promGoodsList[$key1]['full_status'] = 0;
                                $promGoodsList[$key1]['full_text'] = '';
                            }
                        }else{
                            $promGoodsList[$key1]['full_status'] = 1;
                            $promGoodsList[$key1]['full_text'] = '店铺满赠';
                        }
                    }else{
                        $promGoodsList[$key1]['full_status'] = 0;
                        $promGoodsList[$key1]['full_text'] = '';
                    }
                    
                    $prom_goods_price=0;
                    if($this->user_id =='61' || $this->is_lock == 1)
                        $promGoodsList[$key1]['shop_price']='登陆查看'; //浮点计算
    
                    // 首页商品优惠折扣显示 20181123 亮 START
                    if ($d['prom_id']){
                        //$prom_goods = M('prom_goods')->where(array('id'=>$d['prom_id']))->find();
                        $prom_code = C('MYOSS')['url'].$d['prom_code'];
                        $statusss = 1;
                        $datass = time();
                        $d['shop_price']=(float)$d['shop_price']*(float)$d['floating']/100; //浮点计算
    
                            $d['shop_price']+=yj_price_index_home($d['yijia_quyu'],$d['yijia']);
    
                        if (($datass > $d['start_time']) && ($datass < $d['end_time'])){
                            if ($d['type'] == 0){
                                $prom_goods_price = geshi($d['shop_price'] * $d['expression'] / 100);
                                $prom_goods_content = 0;
                            }elseif($d['type'] == 1){
                                $prom_goods_price = $d['shop_price'] - $d['expression'];
                                $prom_goods_content = 0;
                            }elseif($d['type'] == 2){
                                $prom_goods_price = $d['expression'];
                                $prom_goods_content = 0;
                            }else{
                                $prom_goods_price = $d['shop_price'];
                                $prom_goods_content = "购买赠送代金券$d[expression]元";
                            }
                        }
                        if($prom_goods_price){
                            $promGoodsList[$key1]['prom_goods_price'] = geshi($prom_goods_price);
                            $promGoodsList[$key1]['prom_goods_content'] =huodong_name($d['type'],$d['expression']);
                            $promGoodsList[$key1]['prom_code'] = $prom_code;
                            $promGoodsList[$key1]['status_status'] = $statusss;
                            
                             if($this->user_id =='61' || $this->is_lock == 1)
                                 $promGoodsList[$key1]['prom_goods_price']='登陆查看'; //浮点计算
                        }
                    }
                    // 首页商品优惠折扣显示 20181123 亮 END
                }
            exit(json_encode(array('status'=>1,'msg'=>'获取成功','result'=>$promGoodsList))); 
        }else{
            //获取今天的每天秒杀
            $time = time();
            //获取所有每日秒杀id
            $promGoods = M('prom_goods')
                ->where('start_time<'.$time.' and end_time>'.$time.' and miao_status = 1')
                ->select();
            if(!empty($promGoods)){
                $promId = '';
                foreach ($promGoods as $k=>$v){
                    $promId .= $v['id'].',';
                }
                $promId = substr($promId,0,strlen($promId)-1);
                //获取每日秒杀商品按热度排序
                $promGoodsList = M('goods as a')
                    ->field('a.*,b.store_name,c.expression')
                    ->join('ty_store b on b.store_id = a.store_id','LEFT')
                    ->join('ty_prom_goods c on c.id = a.prom_id','LEFT')
                    ->where('a.prom_id in ('.$promId.')')
                    // ->order("c.orderby ASC,a.sales_sum DESC")
                    // ->order('expression asc,a.goods_id')
                    ->order('c.orderby ASC,expression asc,a.goods_id')
                    ->limit($showPage,$limit)
                    ->select();
                
                foreach ($promGoodsList as $k=>$v){//计算价格
                    if($discount){
            			$v['shop_price']=$discount*$v['shop_price'];
            		}
                    //找到优惠力度
                    $prom = M('prom_goods')->where(['id'=>$v['prom_id']])->find();
                    $quyu_price=quyu_price($this->fenbu_id,$v['store_id'],$v['goods_id']);
                    $float = check_float($v['store_id'],$this->user_id,$v['goods_id']);
                    $v['floating'] = $v['floating']+$float;
                    $promGoodsList[$k]['shop_price']=geshi((float)$v['shop_price']*(float)$v['floating']/100*$quyu_price); //浮点计算
                     $goodsFull = M('goods_full')->where("store_id = ".$v['store_id']." and start_time <=$time and end_time >=$time")->order('id desc')->find();
                    if(!empty($goodsFull) && $v['prom_lock'] == 0){
                        if(!empty($goodsFull['brand_id'])){
                            $brand_id = json_decode($goodsFull['brand_id'],true);
                            if(in_array($v['store_cat_id1'],$brand_id)){
                                $promGoodsList[$k]['full_status'] = 1;
                                $promGoodsList[$k]['full_text'] = '店铺满赠';
                            }else{
                                $promGoodsList[$k]['full_status'] = 0;
                                $promGoodsList[$k]['full_text'] = '';
                            }
                        }elseif(!empty($goodsFull['goods_id'])){
                            $goods_id = json_decode($goodsFull['goods_id'],true);
                            if(in_array($v['goods_id'],$goods_id)){
                                $promGoodsList[$k]['full_status'] = 1;
                                $promGoodsList[$k]['full_text'] = '店铺满赠';
                            }else{
                                $promGoodsList[$k]['full_status'] = 0;
                                $promGoodsList[$k]['full_text'] = '';
                            }
                        }else{
                            $promGoodsList[$k]['full_status'] = 1;
                            $promGoodsList[$k]['full_text'] = '店铺满赠';
                        }
                    }else{
                        $promGoodsList[$k]['full_status'] = 0;
                        $promGoodsList[$k]['full_text'] = '';
                    }
                    if(!empty($prom)){
                        //计算优惠价格
                        if($prom['type'] == 5){
                            $promGoodsList[$k]['shop_price'] = $promGoodsList[$k]['shop_price']*$prom['expression']/100;
                        }elseif($prom['type'] == 2){
                            $promGoodsList[$k]['shop_price'] = $prom['expression'];
                        }
                    }


                        $promGoodsList[$k]['shop_price']=$promGoodsList[$k]['shop_price']+yj_price($v['goods_id'],$promGoodsList[$k]['shop_price'],$this->fenbu_id);

                    $promGoodsList[$k]['shop_price'] = geshi($promGoodsList[$k]['shop_price']);
                    if($this->user_id =='61')
                        $promGoodsList[$k]['shop_price'] = '登录查看';

                    $statusss = 1;
                    $prom_goods_price = $promGoodsList[$k]['shop_price'];
                    $prom_goods_content = 0;
                    $promGoodsList[$k]['expression'] = $v['expression'];
                    $promGoodsList[$k]['expressions'] =huodong_name($promGoodsList[$k]['prom_type'],$promGoodsList[$k]['expression']);
                    $promGoodsList[$k]['prom_goods_price'] = \sanwei($prom_goods_price);
                    $promGoodsList[$k]['prom_goods_content'] = $prom_goods_content;
    //                $goods_list[$k]['prom_code'] = $prom_code;
                    $promGoodsList[$k]['status_status'] = $statusss;
                    //查询是否快线店铺
                    $store = M('store')->where(['store_id'=>$v['store_id']])->find();
                    if ($store['fast_flag']){
                        $promGoodsList[$k]['fast_text'] = '快线';
                    }



                    $promGoodsList[$k]['original_img'] = C('MYOSS')['url'].$v['original_img'];
                }
            }else{
                $promGoodsList = [];
            }
            exit(json_encode(array('status'=>1,'msg'=>'获取成功','result'=>$promGoodsList))); 
        }
    }
    //专区活动模板
    public function zhuanqu(){
        if(I("types")=='1'){
            $where = [
                'start_time'=>['lt',time()],
                'end_time'=>['gt',time()],
                'type'=>'2'
            ];
            $template = M('template')->where($where)->find();
            $template['content'] = htmlspecialchars_decode($template['content']);
            $smtp=tpCache("smtp1");
            $hd_content=htmlspecialchars_decode($smtp['smtp1_content']);
            $bg_height=$smtp['bg_height1'];
        }
        else{
            $where = [
                'start_time'=>['lt',time()],
                'end_time'=>['gt',time()],
                'type'=>'3'
            ];
            $template = M('template')->where($where)->find();
            $template['content'] = htmlspecialchars_decode($template['content']);
            $smtp=tpCache("smtp2");
            $hd_content=htmlspecialchars_decode($smtp['smtp2_content']);
            $bg_height=$smtp['bg_height2'];
        }
        exit(json_encode(array('status'=>1,'msg'=>'获取成功','result'=>array('hd_bg'=>$smtp['smtp_bg'],'hd_content'=>$hd_content,'bg_height'=>$bg_height,'hd_bg_new'=>$template['smtp_bg'],'hd_content_new'=>$template['content'],'bg_height_new'=>$template['bg_height']))));
    }
    /**
     * 首页菜单产品
     */
    public function menus()
    {
        $types=M('goods_category')->cache(true,TPSHOP_CACHE_TIME)->where('is_show=1 and is_hot=1 and parent_id='.I('id'))->order('sort_order asc')->select();
		foreach($types as $key=>$v){
			$image=empty($v['image']) ? '/images/mdzp.png' : C('MYOSS')['url'].$v['image'];
			$types[$key]['image']=$image;
		}

		$brand=M('brand')->where("cat_id1 = ".I('id')." and is_hot=1")->order("sort asc")->cache(true,TPSHOP_CACHE_TIME)->select(); //品牌对应
			foreach ($brand as $keys=>$values)
				{
					$brand[$keys]['logo'] = C('MYOSS')['url'].$values['logo'];
				}

				$goods= M('goods')->alias('g')
				->field('g.goods_id,g.goods_name,g.floating,g.original_img,g.shop_price,g.prom_type,g.prom_id,s.store_name')
				->join('ty_store s ON g.store_id=s.store_id','LEFT')
				->where("g.is_hot=1 and g.is_on_sale=1 and g.is_delete=0 and s.store_state=1 and g.cat_id1=".I('id'))
				->order('g.sorts ASC')->limit(20)
				->cache(true,TPSHOP_CACHE_TIME)
				->select();
				foreach($goods as  $key1=> $d){
					$goods[$key1]['original_img'] = C('MYOSS')['url'].$d['original_img'];
					$goods[$key1]['shop_price']=geshi((float)$d['shop_price']*(float)$d['floating']/100); //浮点计算
					// 首页商品优惠折扣显示 20181123 亮 START
                    if ($d['prom_id']){
                        $prom_goods = M('prom_goods')->where(array('id'=>$d['prom_id']))->find();
						$prom_code = C('MYOSS')['url'].$prom_goods['prom_code'];
                        $statusss = 1;
                        $datass = time();
						$d['shop_price']=(float)$d['shop_price']*(float)$d['floating']/100; //浮点计算
                        if (($datass > $prom_goods['start_time']) && ($datass < $prom_goods['end_time'])){
                            if ($prom_goods['type'] == 0){
                                $prom_goods_price = geshi($d['shop_price'] * $prom_goods['expression'] / 100);
                                $prom_goods_content = 0;
                            }elseif($prom_goods['type'] == 1){
                                $prom_goods_price = $d['shop_price'] - $prom_goods['expression'];
                                $prom_goods_content = 0;
                            }elseif($prom_goods['type'] == 2){
                                $prom_goods_price = $prom_goods['expression'];
                                $prom_goods_content = 0;
                            }else{
                                $prom_goods_price = $d['shop_price'];
                                $prom_goods_content = "购买赠送代金券$prom_goods[expression]元";
                            }
                        }
						if($prom_goods_price){
							$goods[$key1]['prom_goods_price'] = $prom_goods_price;
							$goods[$key1]['prom_goods_content'] = huodong_name($prom_goods['type'],$prom_goods['expression']);
							$goods[$key1]['prom_code'] = $prom_code;
							$goods[$key1]['status_status'] = $statusss;
						}
                    }
                    // 首页商品优惠折扣显示 20181123 亮 END
				}

        exit(json_encode(array('status'=>1,'msg'=>'获取成功','types'=>$types,'brand'=>$brand,'goods'=>$goods)));
    }

    /**
     * 获取服务器配置
     */
    public function getConfig()
    {
        $config_arr = M('config')->select();
        exit(json_encode(array('status'=>1,'msg'=>'获取成功','result'=>$config_arr)));
    }

    /**
     * 获取商城菜单
     */
    public function gettab()
    {
        $unique_id = I("session_id"); // 唯一id  类似于 pc 端的session id
        $this->user_id = I("user_id",0); // 用户id
        $where = " session_id = '$unique_id' "; // 默认按照 $unique_id 查询
        $this->user_id && $where = $where ."or user_id = " . $this->user_id; // 如果这个用户已经等了则按照用户id查询

		//兼容修复 购物车数量问题   by  tianxin100  20181109
		$cartNum=0;
		//$cartallinfo=M('Cart')->where($where)->select();
		$cartallinfo = M('Cart')
		->alias('a')
		->join('ty_goods b on a.goods_id=b.goods_id')
		->where(array('b.is_on_sale'=>1,'b.goods_state'=>1))
		->where($where)->select();
		foreach($cartallinfo  as $key=>$value){

			$num = $value['goods_num']*1;
			$cartNum=$cartNum+$num;

		}
        $cartNum =$cartNum && $this->user_id != 61 ? $cartNum :0;
		//兼容修复 购物车数量问题   by  tianxin100  20181109

		$where = " is_show = 1 "; // 默认按照 $unique_id 查询
        $tab_arr = M('navigation_tab')->where($where)->order("sort ASC")->cache(true,TPSHOP_CACHE_TIME)->select();
		foreach($tab_arr  as $key=>$value){
			if($value['url']=="/pages/cart/cart"){
                $tab_arr[$key]['is_shownum']=$cartNum;
            }
			//$tab_arr[$key]['ad_code']=SITE_URL.$value['ad_code'];
			//$tab_arr[$key]['ad_code']=C('MYOSS')['url'].str_replace('/Public/', '',$value['ad_code']);
			$tab_arr[$key]['ad_code']=C('MYOSS')['url'].$value['ad_code'];
		}
		if($tab_arr){
			exit(json_encode(array('code'=>1,'msg'=>'获取成功','result'=>$tab_arr)));
		}else{

			exit(json_encode(array('code'=>0,'msg'=>'获取失败','result'=>$tab_arr)));
		}
    }
    /**
     * 获取插件信息
     */
    public function getPluginConfig()
    {
        $data = M('plugin')->where("type='payment' OR type='login'")->select();
        $arr = array();
        foreach($data as $k=>$v){
            unset( $data[$k]['config']);
            unset( $data[$k]['config']);

            $data[$k]['config_value'] = unserialize($v['config_value']);
            if($data[$k]['type'] == 'payment'){
                $arr['payment'][] =  $data[$k];
            }
            if($data[$k]['type'] == 'login'){
                $arr['login'][] =  $data[$k];
            }
        }
        exit(json_encode(array('status'=>1,'msg'=>'获取成功','result'=>$arr ? $arr : '')));
    }

    public function getCouponInfo($user_id)
    {
        if($user_id && $user_id != 61){
            $coupon = M('coupon')->where(array('use_end_time'=>array('gt',time())))->order("id desc")->select();
            foreach ($coupon as $item){
                $user_coupon = M('coupon_list')->where(array('cid'=>$item['id'],'uid'=>$user_id,'use_time'=>0))->find();

                if($user_coupon){
                    $now = strtotime(date('Y-m-d',time()));
                    $use_end_time = $item['use_end_time'];
                    $diff = (int) (($use_end_time-$now) / 86400);
                    $diff = $diff + 1;
                    if($diff > 0 && $diff <= 3){
                        return $diff;
                    }
                }
            }

            return  0;
        }
    }

	//获取领券中心的优惠券列表
    public function getReceiveCoupon($user_id){

    	$this->user_id = $user_id;
        if($this->user_id){

			// 获取优惠券的信息
			$coupon = M('coupon')->where(array('type'=>4,'use_end_time'=>array('gt',time())))->order("id desc")->select();
			if ($coupon) {
				//设置优惠券的状态 1:已领取,2:未领取,3:已领完
				foreach ($coupon as $k=>$v) {
					$coupon[$k]['use_start_time'] = date('Y-m-d', $v['use_start_time']);
					$coupon[$k]['use_end_time'] = date('Y-m-d', $v['use_end_time']);
					$user_coupon = M('coupon_list')->where(array('cid'=>$v['id'],'uid'=>$this->user_id))->find();
					if ($user_coupon) {
						$coupon[$k]['c_status'] = '1';
						$coupon[$k]['clicked'] = true;
					} else {
						$remain_coupon = M('coupon_list')->where(array('cid'=>$v['id'],'uid'=>0))->find();
						if ($remain_coupon) {
							$coupon[$k]['c_status'] = '2';
							$coupon[$k]['clicked'] = false;
						} else {
							$coupon[$k]['c_status'] = '3';
							$coupon[$k]['clicked'] = true;
						}
					}
				}
			}
		}
		return $coupon;
    }
	//获取拼团商品 首页显示
	public function getPintTypeList(){

		$con =  M('config');
		//是否开启了拼团
		$isPint = $con->where(array('name'=>"pint_can"))->getField('value');
		if(!$isPint){
			return false;
		}
	    $goods= M("goods")->field("goods_id,pt_numed,store_id,goods_name,original_img,pt_price,shop_price,pt_man_num")
                ->where(array("is_pint"=>1,"pt_hot"=>1,"is_on_sale"=>1))->limit('0,4')->select();  //查找拼团商品
	    foreach($goods as $k=>$v){
	    	//$goods[$k]['original_img'] = SITE_URL.$v['original_img'];
			//$goods[$k]['original_img'] = C('MYOSS')['url'].str_replace('/Public/', '',$v['original_img']);
			$goods[$k]['original_img'] = C('MYOSS')['url'].$v['original_img'];
	    }
		if($goods){

			return $goods;

		}else{

			return false;
		}
	}

    /**
     * 今日秒杀商品
     */
    public function goodsLists()
    {
		$time = intval(date('H'));
        $list = M('miaosha_goods')->where(['start_time'=>$time,'open_time'=>date('Y-m-d')])->select();
        if (empty($list)) {
			return false;
        }
        if(date('H').':00' == $_GET['time']){
            $stt = 1;
        }else{
            $stt = 0;
        }

        foreach ($list as $k => $v) {
            $list[$k]['attr'] = json_decode($list[$k]['attr'], true);
            $list[$k]['sell_num'] = M('order_goods')->where(array('prom_type'=>4,'prom_id'=>$v['id']))->getField('sum(goods_num)');
            $list[$k]['stt'] = $stt;
            if(!$list[$k]['sell_num']){
                $list[$k]['sell_num'] = 0;
            }
            if($list[$k]['ms_num'] > $list[$k]['sell_num']){
                $list[$k]['status'] = 1;
            }else{
                $list[$k]['status'] = 0;
                $list[$k]['sell_num'] = 0;
            }
			$list[$k]['attr']['original_img'] = 'https://'.$_SERVER['HTTP_HOST'].$list[$k]['attr']['original_img'];
        }
		return $list;

    }

    /**
     * 获取jdk信息
     */
    public function wx_jdk()
    {
        $url = I('url');
        $weixin_config = M('wx_user')->find(); //获取微信配置
        $jssdk = new Jssdk($weixin_config['appid'],$weixin_config['appsecret']);
        
//        $jssdk = new Jssdk('wx162fb75bc2fed9f2','5e25ac576489e2009215031be50c8325');
        $res = $jssdk->getSignPackage(urldecode($url));
        $res['status'] = 1;
        exit(json_encode($res,JSON_UNESCAPED_SLASHES));
    }

    public function clear_quota(){
        $wechat = M('wx_user')->find();
        $url = "https://api.weixin.qq.com/cgi-bin/clear_quota/v2?appid={$wechat['appid']}&appsecret={$wechat['appsecret']}";
        $return = httpRequest($url,'POST');
        dump($return);
        exit(json_encode($return));
    }
    

    public function panelStoreList() {
        $page = $_POST['page']??1;
        $begin = strtotime(date('Y-m-d', time()) . ' 00:00:00');
        $end = strtotime(date('Y-m-d', strtotime('+1 days', time())) . ' 00:00:00');
        $condition['add_time'] = array('between', "$begin,$end");
        $condition['order_status'] = array('in', [0, 1, 2]);

        $fenbu = M('fenbu')->field('fenbu_id')->select();
        $fenbu_id = array_column($fenbu, 'fenbu_id');
        $condition['ufenbu_id'] = array('in', $fenbu_id);
        $count = M('order a')
        ->field('b.store_name,sum(a.order_amount) as order_price_count,count(a.order_id) as order_count')
        ->join('ty_store b on b.store_id=a.store_id')
        ->where($condition)
        ->group('b.store_id')->select();

        $page_start = $page-1;
    
        //图表3 店铺排名
        $store_order_list = M('order a')
            ->field('b.store_name,sum(a.order_amount) as order_price_count,count(a.order_id) as order_count')
            ->join('ty_store b on b.store_id=a.store_id')
            ->where($condition)
            ->group('b.store_id')->order('order_price_count desc')->limit("{$page_start},30")->select();

        echo json_encode(['count'=>count($count),'data'=>$store_order_list]);
    }
    
    
    

}